< previous page page_732 next page >

Page 732
Table 32.2 Types of Data Supported by the AsyncRead Method
ConstantDescription
vbAsyncTypeFileThe data is contained in a file created by Visual Basic.
vbAsyncTypeByteArrayThe data is a byte array containing retrieved data.
vbAsyncTypePictureThe data is stored in a Picture object.

The CancelAsyncRead method is used to terminate an asynchronous read prior to its completion.
As an example, add an asynchronous read to the ActiveX Document Loan Calculator. Before adding code for the AsyncRead method, set up the project as follows:
1. If you have not already done so, create the sample project described in the preceding sections.
2. Open the CalcDoc UserDocument object, and add two new controls to the form: a second command button and an Image control.
3. Name the command button cmdGetPic, and name the Image control imgMain.
4. Find the path to a picture file on your hard drive or intranet that you can use for this test. In the example, I use D:\Pictures\Brian.BMP.
5. Add the AsyncRead code to the Click event of the command button, as follows:
Private Sub CmdGetPic_Click()
     AsyncRead "d:\pictures\brian.bmp", vbAsyncTypePicture, "MyPicture"
End Sub
The code simply initiates a download of the picture BRIAN.BMP to the client machine. In this case, I specified an exact file path on a local hard drive, but you can also use a URL just as easilyfor example, http://myserver/mypicture.gif.
6. Add the following code to the AsyncReadComplete event of the user document to put the downloaded picture into the Image control:
Private Sub UserDocument_AsyncReadComplete(AsyncProp As AsyncProperty)

MsgBox "The picture download has finished with status " &
AsyncProp.StatusCode
Set imgMain.Picture = AsyncProp.Value

End Sub
The AsyncReadComplete event fires after the picture is downloaded, in which case a message box is displayed and the picture (stored in the parameter AsyncProp) is displayed in the Image control.
note.gif If you are loading an image from the Web (with the http:// syntax), Internet Explorer may cache it locally. To make the most of the cache, you can add an optional parameter to the end of the AsyncRead call to control when and if the cache image is used. For a list of the settings of this parameter, see the AsyncRead method topic in the online help file. square.gif

 
< previous page page_732 next page >